package com.sgb.zhaocai.viewmodel;

import android.app.Application;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import com.sgb.link.entity.PickInvitedApply;
import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.entity.PickInvitedList;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 邀请报名列表页    招标，竞价
 */
public class PickInvitedApplyListModel extends AndroidViewModel {

    public MutableLiveData<Boolean> dialog = new MutableLiveData<>();
    public ObservableField<Integer> page = new ObservableField<>(1);
    public MutableLiveData<String> showToast = new MutableLiveData<>();
    public MutableLiveData<List<PickInvitedList>> pickInvitedList = new MutableLiveData<>();
    public MutableLiveData<List<PickInvitedApply>> pickInvitedApplyList = new MutableLiveData<>();
    private Map map;

    public PickInvitedApplyListModel(@NonNull Application application) {
        super(application);
    }

    //邀请竞价-邀请记录-列表
    public void findInviteList(String customerName) {
        dialog.setValue(true);
        map = new HashMap();
        map.put("page", page.get());
        map.put("limit", 10);
        map.put("customerName",customerName);
        BaseApi.getApi().findInviteList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<PickInvitedList>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<PickInvitedList>>> data) {
                dialog.setValue(false);
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    pickInvitedList.setValue(data.getData().getList());
                } else {
                    if (!TextUtils.isEmpty(data.getMsg())) {
                        showToast.setValue(data.getMsg());
                    }
                    pickInvitedList.setValue(new ArrayList<>());
                }
            }
        });
    }

    //邀请竞价-竞价信息-列表
    public void getFindBidPage(String keyword) {
        dialog.setValue(true);
        map = new HashMap();
        map.put("page", page.get());
        map.put("limit", 10);
        map.put("keyword",keyword);
       BaseApi.getApi().getFindBidPage(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<PickInvitedApply>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<PickInvitedApply>>> data) {
                dialog.setValue(false);
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    pickInvitedApplyList.setValue(data.getData().getList());
                } else {
                    if (!TextUtils.isEmpty(data.getMsg())) {
                        showToast.setValue(data.getMsg());
                    }
                    pickInvitedApplyList.setValue(new ArrayList<>());
                }
            }
        });
    }

    //邀请招标-邀请记录列表-列表
    public void biddingInviteList(String tenderName) {
        dialog.setValue(true);
        map = new HashMap();
        map.put("page", page.get());
        map.put("limit", 10);
        map.put("tenderName",tenderName);
       BaseApi.getApi().biddingInviteList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<PickInvitedList>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<PickInvitedList>>> data) {
                dialog.setValue(false);
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    pickInvitedList.setValue(data.getData().getList());
                } else {
                    if (!TextUtils.isEmpty(data.getMsg())) {
                        showToast.setValue(data.getMsg());
                    }
                    pickInvitedList.setValue(new ArrayList<>());
                }
            }
        });
    }

    //邀请招标-招标信息列表
    public void findSignPage(String tenderName) {
        dialog.setValue(true);
        map = new HashMap();
        map.put("page", page.get());
        map.put("limit", 10);
        map.put("tenderName",tenderName);
       BaseApi.getApi().findSignPage(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<PickInvitedApply>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<PickInvitedApply>>> data) {
                dialog.setValue(false);
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    pickInvitedApplyList.setValue(data.getData().getList());
                } else {
                    if (!TextUtils.isEmpty(data.getMsg())) {
                        showToast.setValue(data.getMsg());
                    }
                    pickInvitedApplyList.setValue(new ArrayList<>());
                }
            }
        });
    }
}

